<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Ann as ModelAnn;
use app\common\model\Banner;

/**
 * 公告接口
 */
class Ann extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /**
     * @Author LK
     * @ApiTitle (公告列表)
     * @ApiMethod (GET)
     * @ApiParams (name="type", type="integer", required=true, sample="", description="1=公告，2=党建工作")
     * @ApiParams (name="state", type="integer", required=true, sample="", description="1=正常，2=推荐")
     * @ApiParams (name="limit", type="integer", required=true, sample="", description="每页数量")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function lists()
    {
        $param = request()->param();
        extract($param);
        $model = new ModelAnn;
        if (!isset($type) || !$type) {
            $this->error('参数错误');
        }
        if ($state != 'all') {
            $model->where('state', $state);
        }

        $list = $model->where('type', $type)->order('id desc')->paginate($limit);
        $this->success('请求成功', $list);
    }
    /**
     * @Author LK
     * @ApiTitle (公告详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function info()
    {
        $id = request()->param('id');
        if (!isset($id) || !$id) {
            $this->error('参数错误');
        }
        $data = ModelAnn::get($id);
        $this->success('请求成功', $data);
    }
}
